package com.tanhua.server.controller;

import com.tanhua.domain.db.Announcement;
import com.tanhua.domain.vo.AnnouncementVo;
import com.tanhua.domain.vo.ContactVo;
import com.tanhua.domain.vo.MessageVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.AnnounService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class AnnounController {
    @Autowired
    private AnnounService announService;

    @GetMapping("/announcements")
    public ResponseEntity announcement(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagegSize", defaultValue = "10") Long pageSize) {
        PageResult<AnnouncementVo> pageResult = announService.announcement(page, pageSize);
        return ResponseEntity.ok(pageResult);
    }
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String,Integer> map){
        announService.addContacts(map);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/contacts")
    public ResponseEntity ContactsL(@RequestParam(value = "page",defaultValue = "1") Long page,
                                   @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize,
                                   String keyword){
     PageResult<ContactVo> pageResult= announService.ContactsList(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/loves")
    public ResponseEntity pageLoves(@RequestParam(value = "page",defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        PageResult<MessageVo> pageResult=announService.pageLoves(page,pagesize,3);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/likes")
    public ResponseEntity pagelikes(@RequestParam(value = "page",defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        PageResult<MessageVo> pageResult=announService.pageLoves(page,pagesize,1);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/comments")
    public ResponseEntity pagecomments(@RequestParam(value = "page",defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        PageResult<MessageVo> pageResult=announService.pageLoves(page,pagesize,2);
        return ResponseEntity.ok(pageResult);
    }
}
